﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Model
{
    public class EntityKey
    {
        private List<ColumnDefine> key_ = new List<ColumnDefine>();
        public List<ColumnDefine> Keys 
        {
            get { return key_; }
            set { key_ = value; }
        }
        public override string ToString()
        {
            if (key_ == null)
                return string.Empty;
            string str = string.Empty;
            foreach (ColumnDefine define in key_)
            {
                str += string.Format("and {0}", define.ToString());
            }
            if (str.Trim().StartsWith("and"))
                str = str.Trim().Substring(3);
            return str;
        }
        public ColumnDefine Find(object value)
        {
            foreach (ColumnDefine col in key_)
            {
                if (col.Value.Equals(value))
                    return col;
            }
            return null;
        }
        public void SetPrimaryKey(object obj)
        {
            if (key_ == null)
                key_ = new List<ColumnDefine>();
            key_[0].Value = obj;
        }
    }
}
